//
//  Math.swift
//  Yip
//
//  Created by bo wang on 2022/6/5.
//  Copyright © 2022 yip.com. All rights reserved.
//

import Foundation
import CoreGraphics

/// 增加计算属性以便可以在数字可选类型上使用点语法

extension CGFloat {
    var ceil: CGFloat { CGFloat(Darwin.ceil(Double(self))) }
    var floor: CGFloat { CGFloat(Darwin.floor(Double(self))) }
    var round: CGFloat { CGFloat(Darwin.round(Double(self))) }
    
    var float: Float { Float(self) }
    var int: Int { Int(self) }
    var double: Double { Double(self) }
    var string: String { "\(self)" }
}

extension Double {
    var ceil: Double { Darwin.ceil(self) }
    var floor: Double { Darwin.floor(self) }
    var round: Double { Darwin.round(self) }
    
    var float: Float { Float(self) }
    var int: Int { Int(self) }
    var cgfloat: CGFloat { CGFloat(self) }
    var string: String { "\(self)" }
}

extension Float {
    var ceil: Float { Darwin.ceilf(self) }
    var floor: Float { Darwin.floorf(self) }
    var round: Float { Darwin.roundf(self) }
    
    var int: Int { Int(self) }
    var double: Double { Double(self) }
    var cgfloat: CGFloat { CGFloat(self) }
    var string: String { "\(self)" }
}

extension Int {
    var float: Float { Float(self) }
    var double: Double { Double(self) }
    var cgfloat: CGFloat { CGFloat(self) }
    var string: String { "\(self)" }
}
